﻿namespace Cuce.ReportingServices
{
    using System;
    using SSRSWS;

    /// <summary>
    /// Wrapper for Unit Testing Reporting Service Reports
    /// </summary>
    public class UnitTestWrapper : TestWrapper
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="UnitTestWrapper"/> class.
        /// </summary>
        /// <param name="value">The actual reporting service proxy</param>
        public UnitTestWrapper(IReportingService value) 
            : base(value)
        {
        }

       /// <summary>
        /// This function will generate the result and result an array list of values
       /// </summary>
       /// <param name="reportName">The report name</param>
       /// <param name="parameterList">An array of Parameters</param>
       /// <param name="dataSource">An array of datasources</param>
        /// <returns>An Array of values</returns>
        public ReportOutputRowCollection TestReport(ReportName reportName, ParameterValue[] parameterList, DataSource[] dataSource)
        {
            if (string.IsNullOrEmpty(ReportServer))
                throw new ArgumentException("Report Server not set", "ReportServer");

            if (reportName == null)
                throw new ArgumentException("Report Name is null", "reportName");

            if (parameterList == null)
                throw new ArgumentException("parameterList is null", "parameterList");

            var result = RenderReport(reportName, parameterList, OutputType.CSV, dataSource);

            return ReportOutputRowCollection.Convert(result, OutputType.CSV);
        }

        /// <summary>
        /// This function will generate the result and result an array list of values
        /// </summary>
        /// <param name="reportName">The name of the report</param>
        /// <returns>A collection of output rows</returns>
        public ReportOutputRowCollection TestReport(ReportName reportName)
        {
            return this.TestReport(reportName, new ParameterValue[] { }, null);
        }

        /// <summary>
        /// This function will generate the result and result an array list of values
        /// </summary>
        /// <param name="reportName">The name of the report</param>
        /// <param name="parameterList">An array of Parameters</param>
        /// <returns>A collection of output rows</returns>
        public ReportOutputRowCollection TestReport(ReportName reportName, ParameterValue[] parameterList)
        {
            return this.TestReport(reportName, parameterList, null);
        }
    }
}
